package com.genius.action;

import java.util.Date;
import java.util.List;

import com.genius.core.manager.StudentManager;
import com.genius.model.Student;
import com.genius.model.StudentLevel;
import com.opensymphony.xwork.ActionSupport;

public class StudentLevelAction extends ActionSupport
{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    private String studentId = null;

    private Student student = null;
    
    StudentManager studentManager = null;
    
    private List studentLevelList = null;
    
    private StudentLevel studentLevel = null;
    

    /**
     * @return Returns the student.
     */
    public Student getStudent()
    {
        return student;
    }

    /**
     * @param student The student to set.
     */
    public void setStudent(Student student)
    {
        this.student = student;
    }

    /**
     * @see com.opensymphony.xwork.ActionSupport#execute()
     */
    public String showAddStudentForm() throws Exception
    {
        this.student = new Student();
        student.setDateOfAddmission(new Date());
        
        //Returns page with student entry form
        return this.SUCCESS;
    }
    
    /**
     * @see com.opensymphony.xwork.ActionSupport#execute()
     */
    public String addStudent() throws Exception
    {
        // Add new student to database.
        studentManager.createStudent(student);
        return this.SUCCESS;
    }

    /**
     * @see com.opensymphony.xwork.ActionSupport#execute()
     */
    public String moveToNextLevel() throws Exception
    {
        // Add new student to database.
        student = studentManager.getStudent(studentId);
        int currentLevel  = student.getCurrentLevelId();
        studentLevel = new StudentLevel();
        studentLevel.setLevelId((long)currentLevel);
        
        return this.SUCCESS;
    }

    public String addStudentLevel()  throws Exception
    {
        studentManager.changeStudentLevel(null, studentLevel);
        return SUCCESS;
    }

    /**
     * @see com.opensymphony.xwork.ActionSupport#execute()
     */
    public String changeLevel() throws Exception
    {
        // Add new student to database.
        student = studentManager.getStudent(studentLevel.getStudentId());
        //student.setCurrentLevelId((int)studentLevel.getLevelId());
        
        int currentLevel  = student.getCurrentLevelId();
        studentLevel = new StudentLevel();
        studentLevel.setLevelId((long)currentLevel);
        return this.SUCCESS;
    }


    
    /**
     * @return Returns the studentManager.
     */
    public StudentManager getStudentManager()
    {
        return studentManager;
    }

    /**
     * @param studentManager The studentManager to set.
     */
    public void setStudentManager(StudentManager studentManager)
    {
        this.studentManager = studentManager;
    }

    /**
     * @return Returns the studentId.
     */
    public String getStudentId()
    {
        return studentId;
    }

    /**
     * @param studentId The studentId to set.
     */
    public void setStudentId(String studentId)
    {
        this.studentId = studentId;
    }

    /**
     * @return Returns the studentLevelList.
     */
    public List getStudentLevelList()
    {
        return studentLevelList;
    }

    /**
     * @param studentLevelList The studentLevelList to set.
     */
    public void setStudentLevelList(List studentLevelList)
    {
        this.studentLevelList = studentLevelList;
    }

    /**
     * @return Returns the studentLevel.
     */
    public StudentLevel getStudentLevel()
    {
        return studentLevel;
    }

    /**
     * @param studentLevel The studentLevel to set.
     */
    public void setStudentLevel(StudentLevel studentLevel)
    {
        this.studentLevel = studentLevel;
    }

    
        
    
}
